package lambda;

import collection.Point;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(13, 2000));
        list.add(new Point(33, 432));
        list.add(new Point(57, 62));
        list.add(new Point(72342, 8234));
        list.add(new Point(944, 107));
        System.out.println("list原始数据：" + list);

        Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int len1 = (int) (Math.pow(o1.getX(), 2) + Math.pow(o1.getY(), 2));
                int len2 = (int) (Math.pow(o2.getX(), 2) + Math.pow(o2.getY(), 2));
                return len1 - len2;//升序
            }
        });
        System.out.println("list排序后数据：" + list);
        Collections.sort(list, (p1, p2) -> {
            int len1 = (int) (Math.pow(p1.getX(), 2) + Math.pow(p1.getY(), 2));
            int len2 = (int) (Math.pow(p2.getX(), 2) + Math.pow(p2.getY(), 2));
            return len1 - len2;//升序
        });
        System.out.println("list排序后数据：" + list);
    }
}
